<?php

declare(strict_types=1);

namespace app\api\controller\ucenter;

use app\api\controller\Api;
use app\common\service\OfficialService;
use app\common\service\WechatService;
use app\common\system\logic\DepartmentLogic;
use app\common\system\logic\UserDepartmentLogic;
use app\common\system\logic\UserLogic;
use app\common\system\logic\UserRoleLogic;
use app\common\system\model\AuthRole;
use think\db\exception\DbException;
use think\facade\Db;
use util\Format;

class Message extends Api
{
    // 用户列表
    public function index()
    {
        $result = [];
        $result['message'] =  '您有新的消息';

        return success($result, '获取数据成功');
    }

    public function sendMsg()
    {
        $post = $this->request->post();
        
        $service = new WechatService();
        $data = $service->sendTplMsg('oifiK7a07Hz0pDKn9mFwHp1_Lao8', '您有新的消息');

        return success($data, '获取数据成功');
    }

    public function sendOfficialMsg()
    {
        $post = $this->request->post();

        $service = new OfficialService();
        $data = [
            'first' => ['value' => '您有新的消息', 'color' => '#173177'],
            'keyword1' => ['value' => '消息内容', 'color' => '#173177'],
            'keyword2' => ['value' => date('Y-m-d H:i:s'), 'color' => '#173177'],
            'remark' => ['value' => '请及时查看。', 'color' => '#173177'],
        ];
        $miniprogram = [
            'appid' => 'wxb14fa06617f17c5e', // your_miniprogram_appid
            'pagepath' => 'pages/index/index',
        ];
        $openid = 'oifiK7a07Hz0pDKn9mFwHp1_Lao8';
        $result = $service->sendTemplateMessage($openid, 'template_id', $data, '', $miniprogram);

        return success($result, '消息发送成功');
    }
}
